package com.erp.programmer.controller;


import com.erp.programmer.bean.CodeMsg;
import com.erp.programmer.dto.IncomingInspectionOrderDto;
import com.erp.programmer.dto.IncomingOrderDto;
import com.erp.programmer.dto.PageDto;
import com.erp.programmer.dto.ResponseDto;
import com.erp.programmer.service.IIncomingOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陈鑫
 * @since 2021-05-27
 */
@RestController
@RequestMapping("/incoming_order")
@CrossOrigin
public class IncomingOrderController {
    @Autowired
    IIncomingOrderService iIncomingOrderService;

    /**
     * 产生入库单
     * @param incomingInspectionOrderDto
     * @return
     */
    @PostMapping("/add")
    public ResponseDto<PageDto<IncomingOrderDto>> insertIncomingOrder(@RequestBody IncomingInspectionOrderDto incomingInspectionOrderDto) {
        if (incomingInspectionOrderDto == null || incomingInspectionOrderDto.getPurchaseId() == null) {
            return ResponseDto.errorByMsg(CodeMsg.DATA_ERROR);
        }
        return iIncomingOrderService.insertIncomingOrder(incomingInspectionOrderDto.getPurchaseId());
    }

    /**
     * 查询入库单
     * @param pageDto
     * @return
     */
    @PostMapping("/get_data")
    public ResponseDto<PageDto<IncomingOrderDto>> getIncomingOrder(@RequestBody PageDto<IncomingOrderDto> pageDto) {
        if (pageDto == null) {
            return ResponseDto.errorByMsg(CodeMsg.DATA_ERROR);
        }
        return iIncomingOrderService.getIncomingOrder(pageDto);
    }
}

